<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" label-position="right" label-width="80px">
        <el-form-item label="createdOn字段:">
          <el-date-picker v-model="formData.createdOn" type="date" placeholder="选择日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="modifiedOn字段:">
          <el-date-picker v-model="formData.modifiedOn" type="date" placeholder="选择日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="card字段:">
          <el-input v-model="formData.card" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="passwd字段:">
          <el-input v-model="formData.passwd" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="orderTime字段:">
          <el-input v-model="formData.orderTime" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="name字段:">
          <el-input v-model="formData.name" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="phoneNumber字段:">
          <el-input v-model="formData.phoneNumber" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="address字段:">
          <el-input v-model="formData.address" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="flag字段:">
          <el-switch v-model="formData.flag" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="order字段:">
          <el-input v-model="formData.order" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="mark字段:">
          <el-switch v-model="formData.mark" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="remark字段:">
          <el-input v-model="formData.remark" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="createdBy字段:">
          <el-input v-model="formData.createdBy" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="modifiedBy字段:">
          <el-input v-model="formData.modifiedBy" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="count字段:">
          <el-input v-model.number="formData.count" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="save">保存</el-button>
          <el-button size="mini" type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  createDzx,
  updateDzx,
  findDzx
} from '@/api/dzx' //  此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
  name: 'Dzx',
  mixins: [infoList],
  data() {
    return {
      type: '',
      formData: {
        createdOn: new Date(),
        modifiedOn: new Date(),
        card: '',
        passwd: '',
        orderTime: '',
        name: '',
        phoneNumber: '',
        address: '',
        flag: false,
        order: '',
        mark: false,
        remark: '',
        createdBy: '',
        modifiedBy: '',
        count: 0,
      }
    }
  },
  async created() {
    // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (this.$route.query.id) {
      const res = await findDzx({ ID: this.$route.query.id })
      if (res.code === 0) {
        this.formData = res.data.redzx
        this.type = 'update'
      }
    } else {
      this.type = 'create'
    }
  },
  methods: {
    async save() {
      let res
      switch (this.type) {
        case 'create':
          res = await createDzx(this.formData)
          break
        case 'update':
          res = await updateDzx(this.formData)
          break
        default:
          res = await createDzx(this.formData)
          break
      }
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: '创建/更改成功'
        })
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style>
</style>
